package edu.mapi.ir.controllers;

import edu.mapi.ir.ciberIF.ciberIF;

/**
 * @author ZP
 */
public class Actuation {

	public double leftPower;
	public double rightPower;
	public boolean returningLed;
	public boolean visitingLed;
	public static int REQUEST_IR0 = 1 << 0 ;
	public static int REQUEST_IR1 = 1 << 1 ;
	public static int REQUEST_IR2 = 1 << 2 ;
	public static int REQUEST_GROUND = 1 << 3 ;
	public static int REQUEST_COMPASS = 1 << 4 ;
	public static int REQUEST_BEACON1 = 1 << 5 ;
	public static int REQUEST_BEACON2 = 1 << 6 ;
	public static int REQUEST_BEACON3 = 1 << 6 ;
	public static int REQUEST_IR3 = 1 << 7 ;
	
	public static int DEFAULT_REQUESTS = REQUEST_IR0 | REQUEST_IR1 | REQUEST_IR2 | REQUEST_COMPASS;
	public int sensor_requests = DEFAULT_REQUESTS;
	
	public Actuation (double leftPower, double rightPower, boolean visitingLed, boolean returningLed, int sensor_requests) {
		this.leftPower = leftPower;
		this.rightPower = rightPower;
		this.returningLed = returningLed;
		this.visitingLed = visitingLed;
		this.sensor_requests = sensor_requests;
	}
	
	public Actuation(double leftPower, double rightPower) {
		this(leftPower, rightPower, false, false, DEFAULT_REQUESTS);
	}
	
	public Actuation(Actuation copy) {
		this.leftPower = copy.leftPower;
		this.rightPower = copy.rightPower;
		this.returningLed = copy.returningLed;
		this.visitingLed = copy.visitingLed;
	}	
	
	public void apply(ciberIF cif) {
		if ((sensor_requests & REQUEST_IR0) != 0)
			cif.RequestIRSensor(0);
		if ((sensor_requests & REQUEST_IR1) != 0)
			cif.RequestIRSensor(1);
		if ((sensor_requests & REQUEST_IR2) != 0)
			cif.RequestIRSensor(2);
		if ((sensor_requests & REQUEST_IR3) != 0)
			cif.RequestIRSensor(3);		
		if ((sensor_requests & REQUEST_COMPASS) != 0)
			cif.RequestCompassSensor();
		if ((sensor_requests & REQUEST_GROUND) != 0)
			cif.RequestGroundSensor();
		if ((sensor_requests & REQUEST_BEACON1) != 0)
			cif.RequestBeaconSensor(0);
		if ((sensor_requests & REQUEST_BEACON2) != 0)
			cif.RequestBeaconSensor(1);
		if ((sensor_requests & REQUEST_BEACON3) != 0)
			cif.RequestBeaconSensor(2);
		
		if (returningLed != cif.GetReturningLed())
			cif.SetReturningLed(returningLed);
		
		if (visitingLed != cif.GetVisitingLed())
			cif.SetVisitingLed(visitingLed);	
		
		cif.DriveMotors(leftPower, rightPower);
		
	}
}
